package prj.carmap.mobile.activity;

import prj.carmap.mobile.CarmapApplication;
import prj.carmap.mobile.R;
import prj.carmap.mobile.model.ServiceItem;
import prj.carmap.mobile.process.AutoServiceProcess;
import prj.carmap.mobile.process.LiveServiceProcess;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.actionbarsherlock.app.ActionBar.LayoutParams;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.miaowang.salad.activity.MineInfoActivity;

/**
 * 商家服务项目界面
 *
 */
public class ServiceItemActivity extends SherlockActivity {
	private ServiceItem currentServiceItem;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		CarmapApplication.addActivity(this);

		//Application app = (Application) this.getApplication();

		setContentView(R.layout.activity_service_detail);
		// Inflate the custom view
		View customNav = LayoutInflater.from(this).inflate(R.layout.nav_view, null);
		// Attach to the action bar
		getSupportActionBar().setDisplayShowCustomEnabled(true);
		getSupportActionBar().setDisplayShowHomeEnabled(false);
		getSupportActionBar().setDisplayShowTitleEnabled(false);

		//
		((TextView) customNav.findViewById(R.id.nav_title)).setText("详情");
		LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
		getSupportActionBar().setCustomView(customNav);
		customNav.setLayoutParams(lp);
		Button returnBtn = (Button) customNav.findViewById(R.id.return_prev);
		returnBtn.setOnClickListener(new Button.OnClickListener() {//创建监听
					public void onClick(View v) {
						ServiceItemActivity.this.finish();
					}
				});
		initMenuItem();

		//TextView sellerName = (TextView) this.findViewById(R.id.seller_name);
		//TextView address = (TextView) this.findViewById(R.id.seller_address);
		//ImageView sellerPic = (ImageView) this.findViewById(R.id.seller_img);

		currentServiceItem = (ServiceItem) this.getIntent().getExtras().get("currentServiceItem");
		TextView name = (TextView) this.findViewById(R.id.service_item_name);
		name.setText(currentServiceItem.serviceItemName);
		TextView desc = (TextView) this.findViewById(R.id.service_item_desc);
		desc.setText(currentServiceItem.serviceItemDesc);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		View view = (View) this.findViewById(R.id.menu_item_home);
		view.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				AutoServiceProcess process = new AutoServiceProcess();
				process.setContext(ServiceItemActivity.this);
				process.getSellerTypes();
			}

		});
		
		view = (View) this.findViewById(R.id.menu_item_type);
		view.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				LiveServiceProcess process = new LiveServiceProcess();
				process.setContext(ServiceItemActivity.this);
				process.getSellerTypes();
			}

		});

		view = (View) this.findViewById(R.id.menu_item_mine);
		view.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
//				UserInfo userInfo = CarmapApplication.getInstance().userInfo;
//				if (userInfo == null) {
//					ServiceItemActivity.this.startActivity(new Intent(
//							ServiceItemActivity.this, LoginActivity.class));
//				} else {
//					ServiceItemActivity.this.startActivity(new Intent(
//							ServiceItemActivity.this, ProfileActivity.class));
//				}
				ServiceItemActivity.this.startActivity(new Intent(
						ServiceItemActivity.this, MineInfoActivity.class));
			}

		});

		return super.onCreateOptionsMenu(menu);
	}

	@SuppressWarnings("deprecation")
	private void initMenuItem() {
		if ("type".equals(CarmapApplication.currentPage)) {
			// 底部菜单项
			View menuItem = this.findViewById(R.id.menu_item_type);
			menuItem.setBackgroundDrawable(getApplication().getResources().getDrawable(R.drawable.bottom_background));
			// 底部菜单图标
			ImageView itemImage = (ImageView) this.findViewById(R.id.item_type_image);
			itemImage.setImageResource(R.drawable.type_select);
			// 底部菜单文字
			TextView itemText = (TextView) this.findViewById(R.id.item_type_text);
			itemText.setTextColor(getApplication().getResources().getColor(R.color.white));
		}
//		else if ("search".equals(CarmapApplication.currentPage)) {
//			// 底部菜单项
//			View menuItem = this.findViewById(R.id.menu_item_search);
//			menuItem.setBackgroundDrawable(getApplication().getResources().getDrawable(R.drawable.bottom_background));
//			// 底部菜单图标
//			ImageView itemImage = (ImageView) this.findViewById(R.id.item_search_image);
//			itemImage.setImageResource(R.drawable.search_select);
//			// 底部菜单文字
//			TextView itemText = (TextView) this.findViewById(R.id.item_search_text);
//			itemText.setTextColor(getApplication().getResources().getColor(R.color.white));
//		}
		else if ("mine".equals(CarmapApplication.currentPage)) {
			// 底部菜单项
			View menuItem = this.findViewById(R.id.menu_item_mine);
			menuItem.setBackgroundDrawable(getApplication().getResources().getDrawable(R.drawable.bottom_background));
			// 底部菜单图标
			ImageView itemImage = (ImageView) this.findViewById(R.id.item_mine_image);
			itemImage.setImageResource(R.drawable.mine_select);
			// 底部菜单文字
			TextView itemText = (TextView) this.findViewById(R.id.item_mine_text);
			itemText.setTextColor(getApplication().getResources().getColor(R.color.white));
		}
		else if ("salad".equals(CarmapApplication.currentPage)) {
			// 底部菜单项
			View menuItem = this.findViewById(R.id.menu_item_salad);
			menuItem.setBackgroundDrawable(getApplication().getResources()
					.getDrawable(R.drawable.bottom_background));
			// 底部菜单图标
			ImageView itemImage = (ImageView) this
					.findViewById(R.id.item_salad_image);
			itemImage.setImageResource(R.drawable.mine_select);
			// 底部菜单文字
			TextView itemText = (TextView) this
					.findViewById(R.id.item_salad_text);
			itemText.setTextColor(getApplication().getResources().getColor(
					R.color.white));
		}
/*		else if ("more".equals(CarmapApplication.currentPage)) {
			// 底部菜单项
			View menuItem = this.findViewById(R.id.menu_item_home);
			menuItem.setBackgroundDrawable(getApplication().getResources().getDrawable(R.drawable.bottom_background));
			// 底部菜单图标
			ImageView itemImage = (ImageView) this.findViewById(R.id.item_home_image);
			itemImage.setImageResource(R.drawable.more_select);
			// 底部菜单文字
			TextView itemText = (TextView) this.findViewById(R.id.item_home_text);
			itemText.setTextColor(getApplication().getResources().getColor(R.color.white));
		}*/
	}
}
